﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Text;
using netDxf;
using netDxf.Blocks;
using netDxf.Collections;
using netDxf.Entities;
using netDxf.Header;
using netDxf.Objects;
using netDxf.Tables;
using netDxf.Units;
using Attribute = netDxf.Entities.Attribute;
using Image = netDxf.Entities.Image;
using Point = netDxf.Entities.Point;
using Trace = netDxf.Entities.Trace;
using System.Threading;

namespace TestDxfDocument
{
    class Hollow_cone_joint_with_flanged_contact_surface
    {
        public static void Hollow_cone_joint(Dictionary<string, Object> data)    //7:24圆锥
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中性线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };  //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层

            //基本参数-----------------------------------------------------------------------------------------------------
            double scale = 1; //放大系数
            double pi = Math.PI;
            string path = Convert.ToString(data["path"]);
            double type = Convert.ToDouble(data["type"]) * scale;

            //定义参数--------------------------------------------------------------------------------------------------
            double b1 = Convert.ToDouble(data["kww"]) * scale;
            double b2 = Convert.ToDouble(data["kww1"]) * scale;
            double b3 = Convert.ToDouble(data["kww2"]) * scale;
            double d1 = Convert.ToDouble(data["dconms"]) * scale;
            double d2 = Convert.ToDouble(data["dfc"]) * scale;
            double d3 = Convert.ToDouble(data["d3"]) * scale;
            double d4 = Convert.ToDouble(data["d4"]) * scale;
            double d5 = Convert.ToDouble(data["d5"]) * scale;
            double d6 = Convert.ToDouble(data["d6"]) * scale;
            double d7 = Convert.ToDouble(data["d7"]) * scale;
            double d8 = Convert.ToDouble(data["d8"]) * scale;
            double d9 = Convert.ToDouble(data["dix"]) * scale;
            double d10 = Convert.ToDouble(data["d10"]) * scale;
            double d11 = Convert.ToDouble(data["d11"]) * scale;
            double d12 = Convert.ToDouble(data["d12"]) * scale;
            double d13 = Convert.ToDouble(data["diout"]) * scale;
            double d14 = Convert.ToDouble(data["dinn"]) * scale;
            double d15 = Convert.ToDouble(data["td"]) * scale;
            double e1 = Convert.ToDouble(data["e1"]) * scale;
            double e2 = Convert.ToDouble(data["e2"]) * scale;
            double f1 = Convert.ToDouble(data["lpcon"]) * scale;
            double f2 = Convert.ToDouble(data["lin"]) * scale;
            double f3 = Convert.ToDouble(data["f3"]) * scale;
            double f4 = Convert.ToDouble(data["f4"]) * scale;
            double f5 = Convert.ToDouble(data["lpcon2"]) * scale;
            double h1 = Convert.ToDouble(data["h1"]) * scale;
            double h2 = Convert.ToDouble(data["h2"]) * scale;
            double h3 = Convert.ToDouble(data["h3"]) * scale;
            double l1 = Convert.ToDouble(data["btel"]) * scale;
            double l2 = Convert.ToDouble(data["ldg"]) * scale;
            double l3 = Convert.ToDouble(data["l3"]) * scale;
            double l4 = Convert.ToDouble(data["l4"]) * scale;
            double l5 = Convert.ToDouble(data["l5"]) * scale;
            double l6 = Convert.ToDouble(data["l6"]) * scale;
            double l7 = Convert.ToDouble(data["l7"]) * scale;
            double l8 = Convert.ToDouble(data["l8"]) * scale;
            double l9 = Convert.ToDouble(data["cbdp"]) * scale;
            double l10 = Convert.ToDouble(data["l10"]) * scale;
            double l11 = Convert.ToDouble(data["l11"]) * scale;
            double l12 = Convert.ToDouble(data["l12"]) * scale;
            double r1 = Convert.ToDouble(data["r1"]) * scale;
            double r2 = Convert.ToDouble(data["r2"]) * scale;
            double r3 = Convert.ToDouble(data["r3"]) * scale;
            double r4 = Convert.ToDouble(data["r4"]) * scale;
            double r5 = Convert.ToDouble(data["r5"]) * scale;
            double r6 = Convert.ToDouble(data["r6"]) * scale;
            double r7 = Convert.ToDouble(data["r7"]) * scale;
            double r8 = Convert.ToDouble(data["r8"]) * scale;
            double r9 = Convert.ToDouble(data["r9"]) * scale;
            double t = Convert.ToDouble(data["t"]) * scale;
            double gc = Convert.ToDouble(data["gc"]) * scale;
            double oxq = Convert.ToDouble(data["oxq"]) * scale;
            double a = Convert.ToDouble(data["ta/2"]);

            //定义点-----------------------------------------------------------------------------------------------------------------------------------
            //第一部分点------------------------------------------------------------------------------
            Vector2 v1 = new Vector2(0, 0);
            Vector2 v2 = new Vector2(v1.X + (l1 + f2), v1.Y);
            Vector2 v5 = new Vector2(5 + l1 - l2, d2 / 2);
            Vector2 v4 = fun.Inters(v5, fun.Polar(v5, -(180 - a) * pi / 180, l1), new Vector2(5 + (r1 - r1 * Math.Cos((90 - a) * pi / 180)), v1.Y + l1), new Vector2(5 + (r1 - r1 * Math.Cos((90 - a) * pi / 180)), v1.Y));
            Vector2 v3 = new Vector2(v1.X + 5, v4.Y - r1 * Math.Sin((90 - a) * pi / 180));
            Vector2 v6 = new Vector2(v5.X + l2 / 2, v5.Y);
            Vector2 v7 = new Vector2(v6.X + l2 / 2, v6.Y);
            Vector2 v8 = new Vector2(v7.X, v1.Y + d1 / 2);
            Vector2 v9 = new Vector2(v8.X + f3 * 3 / 5, v8.Y);
            Vector2 v10 = new Vector2(v9.X + (d1 - d9) / 2 / Math.Tan(60 * pi / 180), v9.Y - (d1 - d9) / 2);
            Vector2 v11 = new Vector2(v10.X + (v10.X - v9.X) * 2, v10.Y);
            Vector2 v37 = new Vector2(v10.X + fun.CalDistance(v10, v11) / 2, v1.Y + fun.CalDistance(v1, v2) / 2);
            Vector2 v38 = fun.mirrorpoint(v37, v1, v2);
            Vector2 v12 = fun.mirrorpoint(v9, v37, v38);
            Vector2 v13 = new Vector2(v8.X + f1, v12.Y);
            Vector2 v14 = new Vector2(v13.X, v13.Y - (d1 - d9) / 2);
            Vector2 v15 = new Vector2(v14.X + f3 / 2, v14.Y);
            Vector2 v16 = fun.mirrorpoint(v15, v1, v2);
            Vector2 v17 = fun.mirrorpoint(v14, v1, v2);
            Vector2 v18 = fun.mirrorpoint(v13, v1, v2);
            Vector2 v19 = fun.mirrorpoint(v12, v1, v2);
            Vector2 v20 = fun.mirrorpoint(v11, v1, v2);
            Vector2 v21 = fun.mirrorpoint(v10, v1, v2);
            Vector2 v22 = fun.mirrorpoint(v9, v1, v2);
            Vector2 v23 = fun.mirrorpoint(v8, v1, v2);
            Vector2 v24 = fun.mirrorpoint(v7, v1, v2);
            Vector2 v25 = fun.mirrorpoint(v6, v1, v2);
            Vector2 v26 = fun.mirrorpoint(v5, v1, v2);
            Vector2 v27 = fun.mirrorpoint(v4, v1, v2);
            Vector2 v28 = fun.mirrorpoint(v3, v1, v2);
            Vector2 v29 = new Vector2(v28.X, v28.Y + d2 / 4);
            Vector2 v30 = fun.Polar(v29, 45 * pi / 180, 1 * scale);
            Vector2 v31 = new Vector2(v30.X + (l4 - r2), v30.Y);
            Vector2 v32 = new Vector2(v31.X + r2, v31.Y + r1);
            Vector2 v33 = fun.mirrorpoint(v32, v1, v2);
            Vector2 v34 = fun.mirrorpoint(v31, v1, v2);
            Vector2 v35 = fun.mirrorpoint(v30, v1, v2);
            Vector2 v36 = fun.mirrorpoint(v29, v1, v2);
            Vector2 v39 = new Vector2(v23.X - l8, v1.Y);
            Vector2 v40 = new Vector2(v14.X, v1.Y + b1 / 2);
            Vector2 v41 = fun.mirrorpoint(v40, v1, v2);
            Vector2 v42 = new Vector2(v40.X - l12 + r9, v40.Y);
            Vector2 v43 = fun.mirrorpoint(v42, v1, v2);

            //第二部分点 
            Vector2 v44 = new Vector2(v2.X + f2, v2.Y);
            Vector2 v45 = new Vector2(v44.X + d1 * 1.2, v2.Y);
            Vector2 v46 = new Vector2(v44.X + fun.CalDistance(v44, v45) / 2, v44.Y + fun.CalDistance(v44, v45) / 2);
            Vector2 v47 = fun.mirrorpoint(v46, v1, v2);
            Vector2 v48 = fun.Inters(v46, v47, v44, v45);
            Vector2 v49 = fun.getPointForArcandLine(new Vector2(v48.X, v48.Y + v40.Y), new Vector2(new Vector2(v48.X, v48.Y + v40.Y).X - d1, new Vector2(v48.X, v48.Y + v40.Y).Y), v48, new Arc(v48, d1 / 2, 90, 180));
            Vector2 v50 = new Vector2(v49.X + (e2 - e1) * 2, v49.Y);
            Vector2 v51 = fun.mirrorpoint(v50, v44, v45);
            Vector2 v52 = fun.mirrorpoint(v49, v44, v45);
            Vector2 v53 = fun.mirrorpoint(v49, v46, v47);
            Vector2 v54 = fun.mirrorpoint(v50, v46, v47);
            Vector2 v55 = fun.mirrorpoint(v51, v46, v47);
            Vector2 v56 = fun.mirrorpoint(v52, v46, v47);
            Vector2 v57 = fun.getPointForArcandLine(new Vector2(v48.X - 5, v48.Y), new Vector2(v48.X - 5, v48.Y + d1), v48, new Arc(v48, d1 / 2, 135, 45));
            Vector2 v58 = new Vector2(v57.X, v57.Y - h3 / 2);
            Vector2 v59 = fun.mirrorpoint(v58, v46, v47);
            Vector2 v60 = fun.mirrorpoint(v57, v46, v47);
            Vector2 v61 = fun.getPointForArcandLine(new Vector2(v48.X - 5 - 1, v48.Y), new Vector2(v48.X - 5 - 1, v48.Y + d1), v48, new Arc(v48, d1 / 2, 135, 45));
            Vector2 v62 = fun.Polar(v61, -88 * pi / 180, h3 / 2 * 1.05);
            Vector2 v63 = fun.mirrorpoint(v62, v46, v47);
            Vector2 v64 = fun.mirrorpoint(v61, v46, v47);
            Vector2 v65 = fun.getPointForArcandLine(v48, fun.Polar(v48, 153 * pi / 180, d1), v48, new Arc(v48, v3.Y - (v4.Y - v3.Y) / 2, 90, 180));
            Vector2 v66 = fun.getPointForArcandLine(v48, fun.Polar(v48, 153 * pi / 180, d1), v48, new Arc(v48, fun.CalDistance(v3, v28) / 2.5, 90, 180));
            Vector2 v67 = new Vector2(v65.X, v66.Y);
            Vector2 v68 = fun.getPointForArcandLine(v48, fun.Polar(v48, 153 * pi / 180, d1), v48, new Arc(v48, fun.CalDistance(v5, v26) / 2, 90, 180));
            Vector2 v69 = fun.mirrorpoint(v65, v46, v47);
            Vector2 v70 = fun.mirrorpoint(v66, v46, v47);
            Vector2 v71 = fun.mirrorpoint(v67, v46, v47);
            Vector2 v72 = fun.mirrorpoint(v68, v46, v47);
            Vector2 v73 = fun.mirrorpoint(v69, v44, v45);
            Vector2 v74 = fun.mirrorpoint(v70, v44, v45);
            Vector2 v75 = fun.mirrorpoint(v71, v44, v45);
            Vector2 v76 = fun.mirrorpoint(v72, v44, v45);
            Vector2 v77 = fun.mirrorpoint(v66, v44, v45);
            Vector2 v78 = fun.mirrorpoint(v67, v44, v45);
            Vector2 v79 = fun.mirrorpoint(v68, v44, v45);

            if (type == 1/*type.Equals("A型空心锥柄")*/)
            {
                //作图部分-------------------------------------------------------------------------------------------------
                //第一部分--------------------------------------------------------------------------------------------
                //中心线
                Line centre_line1 = new Line(v1, v2);
                centre_line1.Layer = centre;
                centre_line1.Linetype = Linetype.Center;
                centre_line1.LinetypeScale = 5;
                dxf.AddEntity(centre_line1);

                Line centre_line2 = new Line(v37, v38);
                centre_line2.Layer = centre;
                centre_line2.Linetype = Linetype.Center;
                centre_line2.LinetypeScale = 5;
                dxf.AddEntity(centre_line2);

                //轮廓线
                LwPolyline polyline1 = new LwPolyline();
                polyline1.Vertexes.Add(new LwPolylineVertex(v3));
                polyline1.Vertexes.Add(new LwPolylineVertex(v4));//0
                polyline1.Vertexes.Add(new LwPolylineVertex(v5));//1
                polyline1.Vertexes.Add(new LwPolylineVertex(v6));//2
                polyline1.Vertexes.Add(new LwPolylineVertex(v7));//3
                polyline1.Vertexes.Add(new LwPolylineVertex(v8));//4
                polyline1.Vertexes.Add(new LwPolylineVertex(v9));//5
                polyline1.Vertexes.Add(new LwPolylineVertex(v10));//6
                polyline1.Vertexes.Add(new LwPolylineVertex(v11));//7
                polyline1.Vertexes.Add(new LwPolylineVertex(v12));//8
                polyline1.Vertexes.Add(new LwPolylineVertex(v13));//9
                polyline1.Vertexes.Add(new LwPolylineVertex(v14));//10
                polyline1.Vertexes.Add(new LwPolylineVertex(v15));//11
                polyline1.Vertexes[0].Bulge = -Math.Tan((90 - a) * pi / 180 / 4);
                polyline1.Vertexes[3].Bulge = Math.Tan((10) * pi / 180 / 4);
                fun.PolyFill(dxf, polyline1, 0.3, contour);

                LwPolyline polyline2 = new LwPolyline();
                polyline2.Vertexes.Add(new LwPolylineVertex(v16));
                polyline2.Vertexes.Add(new LwPolylineVertex(v17));//0
                polyline2.Vertexes.Add(new LwPolylineVertex(v18));//1
                polyline2.Vertexes.Add(new LwPolylineVertex(v19));//2
                polyline2.Vertexes.Add(new LwPolylineVertex(v20));//3
                polyline2.Vertexes.Add(new LwPolylineVertex(v21));//4
                polyline2.Vertexes.Add(new LwPolylineVertex(v22));//5
                polyline2.Vertexes.Add(new LwPolylineVertex(v23));//6
                polyline2.Vertexes.Add(new LwPolylineVertex(v24));//7
                polyline2.Vertexes.Add(new LwPolylineVertex(v25));//8
                polyline2.Vertexes.Add(new LwPolylineVertex(v26));//9
                polyline2.Vertexes.Add(new LwPolylineVertex(v27));//10
                polyline2.Vertexes.Add(new LwPolylineVertex(v28));//11
                polyline2.Vertexes.Add(new LwPolylineVertex(v29));//12
                polyline2.Vertexes.Add(new LwPolylineVertex(v30));//13
                polyline2.Vertexes.Add(new LwPolylineVertex(v31));//14
                polyline2.Vertexes.Add(new LwPolylineVertex(v32));//15
                polyline2.Vertexes.Add(new LwPolylineVertex(v33));//16
                polyline2.Vertexes.Add(new LwPolylineVertex(v34));//17
                polyline2.Vertexes.Add(new LwPolylineVertex(v35));//18
                polyline2.Vertexes.Add(new LwPolylineVertex(v36));//19
                polyline2.Vertexes.Add(new LwPolylineVertex(v3));//20
                polyline2.Vertexes[11].Bulge = -Math.Tan((90 - a) * pi / 180 / 4);
                polyline2.Vertexes[8].Bulge = Math.Tan((10) * pi / 180 / 4);
                polyline2.Vertexes[15].Bulge = Math.Tan((90) * pi / 180 / 4);
                polyline2.Vertexes[17].Bulge = Math.Tan((90) * pi / 180 / 4);
                fun.PolyFill(dxf, polyline2, 0.3, contour);

                LwPolyline polyline3 = new LwPolyline();
                polyline3.Vertexes.Add(new LwPolylineVertex(v14));
                polyline3.Vertexes.Add(new LwPolylineVertex(v17));
                fun.PolyFill(dxf, polyline3, 0.3, contour);

                LwPolyline polyline4 = new LwPolyline();
                polyline4.Vertexes.Add(new LwPolylineVertex(v7));
                polyline4.Vertexes.Add(new LwPolylineVertex(v24));
                fun.PolyFill(dxf, polyline4, 0.3, contour);

                LwPolyline polyline5 = new LwPolyline();
                polyline5.Vertexes.Add(new LwPolylineVertex(v6));
                polyline5.Vertexes.Add(new LwPolylineVertex(v25));
                fun.PolyFill(dxf, polyline5, 0.3, contour);

                LwPolyline polyline6 = new LwPolyline();
                polyline6.Vertexes.Add(new LwPolylineVertex(v40));
                polyline6.Vertexes.Add(new LwPolylineVertex(v42));
                polyline6.Vertexes.Add(new LwPolylineVertex(v43));
                polyline6.Vertexes.Add(new LwPolylineVertex(v41));
                polyline6.Vertexes[1].Bulge = Math.Tan(180 * pi / 180 / 4);
                fun.PolyFill(dxf, polyline6, 0.3, contour);

                LwPolyline polyline7 = new LwPolyline();//右侧样条曲线
                polyline7.Vertexes.Add(new LwPolylineVertex(v15));
                polyline7.Vertexes.Add(new LwPolylineVertex(fun.Inters(v15, new Vector2(v15.X, v15.Y - d9), v1, v2)));
                polyline7.Vertexes.Add(new LwPolylineVertex(v16));
                polyline7.Vertexes[0].Bulge = Math.Tan(40 * pi / 180 / 4);
                polyline7.Vertexes[1].Bulge = -Math.Tan(40 * pi / 180 / 4);
                fun.PolyFill(dxf, polyline7, 0.1, contour);

                fun.drawcircle(dxf, v39, d8 / 2, 0.3, contour);

                //第二部分
                //中心线
                Line centre_line3 = new Line(v44, v45);
                centre_line3.Layer = centre;
                centre_line3.Linetype = Linetype.Center;
                centre_line3.LinetypeScale = 5;
                dxf.AddEntity(centre_line3);

                Line centre_line4 = new Line(v46, v47);
                centre_line4.Layer = centre;
                centre_line4.Linetype = Linetype.Center;
                centre_line4.LinetypeScale = 5;
                dxf.AddEntity(centre_line4);

                //轮廓线
                fun.drawcircle(dxf, v48, fun.CalDistance(v32, v33) / 2, 0.3, contour);
                fun.drawcircle(dxf, v48, fun.CalDistance(v31, v34) / 2, 0.3, contour);
                fun.drawcircle(dxf, v48, fun.CalDistance(v3, v28) / 2.5, 0.3, contour);
                fun.drawcircle(dxf, v48, fun.CalDistance(v5, v26) / 2, 0.3, contour);
                fun.drawcircle(dxf, v48, fun.CalDistance(v8, v23) / 2, 0.3, contour);

                Circle circle1 = new Circle(v48, v3.Y - (v4.Y - v3.Y) / 2);
                circle1.Layer = refin;
                circle1.Linetype = Linetype.Dashed;
                circle1.LinetypeScale = 5;
                dxf.AddEntity(circle1);

                LwPolyline polyline8 = new LwPolyline();
                polyline8.Vertexes.Add(new LwPolylineVertex(v57));
                polyline8.Vertexes.Add(new LwPolylineVertex(v58));
                polyline8.Vertexes.Add(new LwPolylineVertex(v59));
                polyline8.Vertexes.Add(new LwPolylineVertex(v60));
                fun.PolyFill(dxf, polyline8, 0.3, contour);

                LwPolyline polyline9 = new LwPolyline();//上侧样条曲线
                polyline9.Vertexes.Add(new LwPolylineVertex(v61));
                polyline9.Vertexes.Add(new LwPolylineVertex(v62));
                polyline9.Vertexes.Add(new LwPolylineVertex(v63));
                polyline9.Vertexes.Add(new LwPolylineVertex(v64));
                polyline9.Vertexes[0].Bulge = -Math.Tan(10 * pi / 180 / 4);
                polyline9.Vertexes[1].Bulge = Math.Tan(10 * pi / 180 / 4);
                polyline9.Vertexes[2].Bulge = Math.Tan(10 * pi / 180 / 4);
                fun.PolyFill(dxf, polyline9, 0.1, additionalline);

                LwPolyline polyline10 = new LwPolyline();
                polyline10.Vertexes.Add(new LwPolylineVertex(v66));
                polyline10.Vertexes.Add(new LwPolylineVertex(v67));
                polyline10.Vertexes.Add(new LwPolylineVertex(v68));
                polyline10.Vertexes[1].Bulge = -Math.Tan(90 * pi / 180 / 4);
                fun.PolyFill(dxf, polyline10, 0.3, contour);

                LwPolyline polyline11 = new LwPolyline();
                polyline11.Vertexes.Add(new LwPolylineVertex(v70));
                polyline11.Vertexes.Add(new LwPolylineVertex(v71));
                polyline11.Vertexes.Add(new LwPolylineVertex(v72));
                polyline11.Vertexes[1].Bulge = Math.Tan(90 * pi / 180 / 4);
                fun.PolyFill(dxf, polyline11, 0.3, contour);

                LwPolyline polyline12 = new LwPolyline();
                polyline12.Vertexes.Add(new LwPolylineVertex(v74));
                polyline12.Vertexes.Add(new LwPolylineVertex(v75));
                polyline12.Vertexes.Add(new LwPolylineVertex(v76));
                polyline12.Vertexes[1].Bulge = -Math.Tan(90 * pi / 180 / 4);
                fun.PolyFill(dxf, polyline12, 0.3, contour);

                LwPolyline polyline13 = new LwPolyline();
                polyline13.Vertexes.Add(new LwPolylineVertex(v77));
                polyline13.Vertexes.Add(new LwPolylineVertex(v78));
                polyline13.Vertexes.Add(new LwPolylineVertex(v79));
                polyline13.Vertexes[1].Bulge = Math.Tan(90 * pi / 180 / 4);
                fun.PolyFill(dxf, polyline13, 0.3, contour);

                //虚线
                Line line1 = new Line(v49, v50);
                line1.Layer = refin;
                line1.Linetype = Linetype.Dashed;
                line1.LinetypeScale = 1;
                dxf.AddEntity(line1);

                Line line2 = new Line(v50, v51);
                line2.Layer = refin;
                line2.Linetype = Linetype.Dashed;
                line2.LinetypeScale = 1;
                dxf.AddEntity(line2);

                Line line3 = new Line(v51, v52);
                line3.Layer = refin;
                line3.Linetype = Linetype.Dashed;
                line3.LinetypeScale = 1;
                dxf.AddEntity(line3);

                Line line4 = new Line(v53, v54);
                line4.Layer = refin;
                line4.Linetype = Linetype.Dashed;
                line4.LinetypeScale = 1;
                dxf.AddEntity(line4);

                Line line5 = new Line(v54, v55);
                line5.Layer = refin;
                line5.Linetype = Linetype.Dashed;
                line5.LinetypeScale = 1;
                dxf.AddEntity(line5);

                Line line6 = new Line(v55, v56);
                line6.Layer = refin;
                line6.Linetype = Linetype.Dashed;
                line6.LinetypeScale = 1;
                dxf.AddEntity(line6);

                Line line7 = new Line(v65, v73);
                line7.Layer = refin;
                line7.Linetype = Linetype.Dashed;
                line7.LinetypeScale = 1;
                dxf.AddEntity(line7);

                //填充
                LwPolyline hatchpoly1 = new LwPolyline();
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(v61));
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(v62));//0
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(v63));//1
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(v64));//2
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(v60));//3
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(v59));//4
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(v58));//5
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(v57));//6
                hatchpoly1.Vertexes.Add(new LwPolylineVertex(v61));//7
                hatchpoly1.Vertexes[0].Bulge = -Math.Tan(10 * pi / 180 / 4);
                hatchpoly1.Vertexes[1].Bulge = Math.Tan(10 * pi / 180 / 4);
                hatchpoly1.Vertexes[2].Bulge = Math.Tan(10 * pi / 180 / 4);
                hatchpoly1.Vertexes[3].Bulge = Math.Tan(5 * pi / 180 / 4);
                hatchpoly1.Vertexes[7].Bulge = Math.Tan(5 * pi / 180 / 4);
                hatchpoly1.IsClosed = true;
                String[] htype1 = new String[100];
                Line[] hline1 = new Line[100];
                Arc[] harc1 = new Arc[100];
                int hnumst1 = hatchpoly1.Explode().Count;  //记录爆炸后，线段有多少
                for (int i = 0; i < hnumst1; i++)
                {
                    htype1[i] = hatchpoly1.Explode()[i].Type.ToString();    //将所有的元素记录成一个数组
                    if (htype1[i] == "Line")
                    {
                        hline1[i] = (Line)hatchpoly1.Explode()[i];
                    }
                    if (htype1[i] == "Arc")
                    {
                        harc1[i] = (Arc)hatchpoly1.Explode()[i];
                    }
                }
                fun.hatchsub1(dxf, htype1, hnumst1, 45, 2, hline1, harc1, hatching);

                //标注
                //定义
                double height = 1;
                double arrowsize = 1;
                double exline = 1;

                //第一部分
                //直线标注
                //上侧
                fun.dimrot1(dxf, v8, v37, 0, 10, 1, height, arrowsize, exline, "f3=" + Math.Round(f3, 1), "", "");
                fun.dimrot1(dxf, v5, v8, 0, 10, 1, height, arrowsize, exline, "l2=" + Math.Round(l2, 1), "", "");
                //下侧
                fun.dimrot1(dxf, v39, v23, 180, 10, 1, height, arrowsize, exline, "l8=" + Math.Round(l8, 1), "", "");
                fun.dimrot1(dxf, new Vector2(v42.X - r9, v42.Y - r9), v18, 180, 5, 1, height, arrowsize, exline, "l12=" + Math.Round(l12, 1), "", "");
                fun.dimrot1(dxf, new Vector2(v39.X - d8 / 2, v39.Y), new Vector2(v39.X + d8 / 2, v39.Y), 180, 25, 1, height, arrowsize, exline, "φd8=" + Math.Round(d8, 1), "", "");
                fun.dimrot1(dxf, v23, v18, 180, 10, 1, height, arrowsize, exline, "f1=" + Math.Round(f1, 1), "", "");
                fun.dimrot1(dxf, v28, v23, 180, 20, 1, height, arrowsize, exline, "l1=" + Math.Round(l1, 1), "", "");
                fun.dimrot1(dxf, new Vector2(v16.X - 2, v16.Y), v23, 180, 20, 1, height, arrowsize, 5, "f2=" + Math.Round(f2, 1), "", "");
                fun.dimrot1(dxf,v29, v32, 180, 5, 1, height, arrowsize, exline, "l4=" + Math.Round(l4, 1), "", "");
                //左侧
                fun.dimrot1(dxf, v5, v26, 90, 20, 1, height, arrowsize, exline, "φd2=" + Math.Round(d2, 1), "", "");
                //右侧
                fun.dimrot1(dxf, v15, v16, -90, 5, 1, height, arrowsize, exline, "φd9=" + Math.Round(d9, 1), "", "");
                fun.dimrot1(dxf, v13, v18, -90, 20, 1, height, arrowsize, exline, "φd1=" + Math.Round(d1, 1), "", "");

                //箭头
                fun.jt1(dxf, v34, -135, 5, 1, "r2", height);
                fun.jt1(dxf, v42, 135, 5, 1, "r9", height);
                fun.jt1(dxf, v3, 135, 5, 1, "r1", height);

                //形位公差
                fun.gcbz(dxf, new Vector2(v23.X, v23.Y - 22), 5, 180, 0.1, 180, 4, arrowsize, 1, "A", "0.002", height, "qtd", 0.5);

                //第二部分
                //直线标注
                //上侧
                fun.dimrot1(dxf, v68, v46, 0, 25, 1, height, arrowsize, exline, "e2=" + Math.Round(e2, 1), "", "");
                fun.dimrot1(dxf, v65, v46, 0, 20, 1, height, arrowsize, exline, "e1=" + Math.Round(e1, 1), "", "");
                fun.dimrot1(dxf, v57, v60, 0, 10, 1, height, arrowsize, exline, "φ10", "+0.09", "0");
                //左侧
                fun.dimrot1(dxf, new Vector2(v48.X, v48.Y + d1 / 2), v58, 90, 20, 1, height, arrowsize, exline, "h3=" + Math.Round(h3, 1), "", "");
                fun.dimrot1(dxf, v67, v78, 90, 20, 1, height, arrowsize, exline, "b1=" + Math.Round(b1, 1), "", "");

                //角度标注
                fun.jdbz2(dxf, new Line(v66, fun.Polar(v66, 153 * pi / 180, 0.1)), new Line(v48, new Vector2(v48.X - 0.1, v48.Y)), 25, height, arrowsize, exline, "27°±3°", "", "");

                //形位公差
                fun.gcbz(dxf, new Vector2(v78.X - 15, v78.Y), 20, -90, 3, 0, 5, arrowsize, 1, "A", "0.05", height, "dcd", 0.5);

                //基准
                fun.jz(dxf, new Vector2(v45.X, v45.Y), -90, 5, "B");

            }

            if (type == 3/*type.Equals("C型空心锥柄")*/)
            {
                //作图部分-------------------------------------------------------------------------------------------------
                //第一部分--------------------------------------------------------------------------------------------
                //中心线
                Line centre_line1 = new Line(v1, v2);
                centre_line1.Layer = centre;
                centre_line1.Linetype = Linetype.Center;
                centre_line1.LinetypeScale = 5;
                dxf.AddEntity(centre_line1);

                //轮廓线
                LwPolyline polyline1 = new LwPolyline();
                polyline1.Vertexes.Add(new LwPolylineVertex(v3));
                polyline1.Vertexes.Add(new LwPolylineVertex(v4));//0
                polyline1.Vertexes.Add(new LwPolylineVertex(v5));//1
                polyline1.Vertexes.Add(new LwPolylineVertex(v6));//2
                polyline1.Vertexes.Add(new LwPolylineVertex(v7));//3
                polyline1.Vertexes.Add(new LwPolylineVertex(v8));//4
                polyline1.Vertexes.Add(new LwPolylineVertex(v9));//5
                polyline1.Vertexes.Add(new LwPolylineVertex(v22));//6
                polyline1.Vertexes.Add(new LwPolylineVertex(v23));//7
                polyline1.Vertexes.Add(new LwPolylineVertex(v24));//8
                polyline1.Vertexes.Add(new LwPolylineVertex(v25));//9
                polyline1.Vertexes.Add(new LwPolylineVertex(v26));//10
                polyline1.Vertexes.Add(new LwPolylineVertex(v27));//11
                polyline1.Vertexes.Add(new LwPolylineVertex(v28));//12
                polyline1.Vertexes.Add(new LwPolylineVertex(v29));//13
                polyline1.Vertexes.Add(new LwPolylineVertex(v30));//14
                polyline1.Vertexes.Add(new LwPolylineVertex(v31));//15
                polyline1.Vertexes.Add(new LwPolylineVertex(v32));//16
                polyline1.Vertexes.Add(new LwPolylineVertex(v33));//17
                polyline1.Vertexes.Add(new LwPolylineVertex(v34));//18
                polyline1.Vertexes.Add(new LwPolylineVertex(v35));//19
                polyline1.Vertexes.Add(new LwPolylineVertex(v36));//20
                polyline1.Vertexes.Add(new LwPolylineVertex(v3));//21
                polyline1.Vertexes[0].Bulge = -Math.Tan((90 - a) * pi / 180 / 4);
                polyline1.Vertexes[3].Bulge = Math.Tan((10) * pi / 180 / 4);
                polyline1.Vertexes[9].Bulge = Math.Tan((10) * pi / 180 / 4);
                polyline1.Vertexes[12].Bulge = Math.Tan((90 - a) * pi / 180 / 4);
                fun.PolyFill(dxf, polyline1, 0.3, contour);

                LwPolyline polyline4 = new LwPolyline();
                polyline4.Vertexes.Add(new LwPolylineVertex(v7));
                polyline4.Vertexes.Add(new LwPolylineVertex(v24));
                fun.PolyFill(dxf, polyline4, 0.3, contour);

                LwPolyline polyline5 = new LwPolyline();
                polyline5.Vertexes.Add(new LwPolylineVertex(v6));
                polyline5.Vertexes.Add(new LwPolylineVertex(v25));
                fun.PolyFill(dxf, polyline5, 0.3, contour);

                Circle circle1 = new Circle(v48, v3.Y - (v4.Y - v3.Y) / 2);
                circle1.Layer = refin;
                circle1.Linetype = Linetype.Dashed;
                circle1.LinetypeScale = 5;
                dxf.AddEntity(circle1);

                fun.drawcircle(dxf, v39, d8 / 2, 0.3, contour);

                //第二部分-----------------------------------------------------------------
                //中心线
                Line centre_line3 = new Line(v44, v45);
                centre_line3.Layer = centre;
                centre_line3.Linetype = Linetype.Center;
                centre_line3.LinetypeScale = 5;
                dxf.AddEntity(centre_line3);

                Line centre_line4 = new Line(v46, v47);
                centre_line4.Layer = centre;
                centre_line4.Linetype = Linetype.Center;
                centre_line4.LinetypeScale = 5;
                dxf.AddEntity(centre_line4);

                //轮廓线
                fun.drawcircle(dxf, v48, fun.CalDistance(v32, v33) / 2, 0.3, contour);
                fun.drawcircle(dxf, v48, fun.CalDistance(v31, v34) / 2, 0.3, contour);
                fun.drawcircle(dxf, v48, fun.CalDistance(v3, v28) / 2.5, 0.3, contour);
                fun.drawcircle(dxf, v48, fun.CalDistance(v5, v26) / 2, 0.3, contour);
                fun.drawcircle(dxf, v48, fun.CalDistance(v8, v23) / 2, 0.3, contour);

                LwPolyline polyline10 = new LwPolyline();
                polyline10.Vertexes.Add(new LwPolylineVertex(v66));
                polyline10.Vertexes.Add(new LwPolylineVertex(v67));
                polyline10.Vertexes.Add(new LwPolylineVertex(v68));
                polyline10.Vertexes[1].Bulge = -Math.Tan(90 * pi / 180 / 4);
                fun.PolyFill(dxf, polyline10, 0.3, contour);

                LwPolyline polyline11 = new LwPolyline();
                polyline11.Vertexes.Add(new LwPolylineVertex(v70));
                polyline11.Vertexes.Add(new LwPolylineVertex(v71));
                polyline11.Vertexes.Add(new LwPolylineVertex(v72));
                polyline11.Vertexes[1].Bulge = Math.Tan(90 * pi / 180 / 4);
                fun.PolyFill(dxf, polyline11, 0.3, contour);

                LwPolyline polyline12 = new LwPolyline();
                polyline12.Vertexes.Add(new LwPolylineVertex(v74));
                polyline12.Vertexes.Add(new LwPolylineVertex(v75));
                polyline12.Vertexes.Add(new LwPolylineVertex(v76));
                polyline12.Vertexes[1].Bulge = -Math.Tan(90 * pi / 180 / 4);
                fun.PolyFill(dxf, polyline12, 0.3, contour);

                LwPolyline polyline13 = new LwPolyline();
                polyline13.Vertexes.Add(new LwPolylineVertex(v77));
                polyline13.Vertexes.Add(new LwPolylineVertex(v78));
                polyline13.Vertexes.Add(new LwPolylineVertex(v79));
                polyline13.Vertexes[1].Bulge = Math.Tan(90 * pi / 180 / 4);
                fun.PolyFill(dxf, polyline13, 0.3, contour);

                //虚线
                Line line7 = new Line(v65, v73);
                line7.Layer = refin;
                line7.Linetype = Linetype.Dashed;
                line7.LinetypeScale = 1;
                dxf.AddEntity(line7);

                Circle circle2 = new Circle(new Vector2(v9.X - d8 / 2 - 1, v39.Y), d8 / 2 - 0.5);
                circle2.Layer = refin;
                circle2.Linetype = Linetype.Dashed;
                circle2.LinetypeScale = 1;
                dxf.AddEntity(circle2);

                //标注
                //定义
                double height = 1;
                double arrowsize = 1;
                double exline = 1;

                //第一部分
                //直线标注
                //上侧
                fun.dimrot1(dxf, v5, v8, 0, 10, 1, height, arrowsize, exline, "l2=" + Math.Round(l2, 1), "", "");
                //下侧
                fun.dimrot1(dxf, v39, v23, 180, 10, 1, height, arrowsize, exline, "l8=" + Math.Round(l8, 1), "", "");
                fun.dimrot1(dxf, new Vector2(v39.X - d8 / 2, v39.Y), new Vector2(v39.X + d8 / 2, v39.Y), 180, 25, 1, height, arrowsize, exline, "φd8=" + Math.Round(d8, 1), "", "");
                fun.dimrot1(dxf, v23, v22, 180, 10, 1, height, arrowsize, exline, "f5=" + Math.Round(f5, 1), "", "");
                fun.dimrot1(dxf, v28, v23, 180, 20, 1, height, arrowsize, exline, "l1=" + Math.Round(l1, 1), "", "");
                fun.dimrot1(dxf, v29, v32, 180, 5, 1, height, arrowsize, exline, "l4=" + Math.Round(l4, 1), "", "");
                //左侧
                fun.dimrot1(dxf, v5, v26, 90, 20, 1, height, arrowsize, exline, "φd2=" + Math.Round(d2, 1), "", "");
                //右侧
                fun.dimrot1(dxf, v9, v22, -90, 20, 1, height, arrowsize, exline, "φd1=" + Math.Round(d1, 1), "", "");

                //箭头
                fun.jt1(dxf, v34, -135, 5, 1, "r2", height);
                fun.jt1(dxf, v3, 135, 5, 1, "r1", height);

                //形位公差
                fun.gcbz(dxf, new Vector2(v23.X, v23.Y - 22), 5, 180, 0.1, 180, 4, arrowsize, 1, "A", "0.002", height, "qtd", 0.5);
                Line line1 = new Line(v23, new Vector2(v23.X, v23.Y - 25));
                line1.Layer = dimensioning;
                dxf.AddEntity(line1);

                //第二部分
                //直线标注
                //上侧
                fun.dimrot1(dxf, v68, v46, 0, 25, 1, height, arrowsize, exline, "e2=" + Math.Round(e2, 1), "", "");
                fun.dimrot1(dxf, v65, v46, 0, 20, 1, height, arrowsize, exline, "e1=" + Math.Round(e1, 1), "", "");
                //左侧
                fun.dimrot1(dxf, new Vector2(v48.X, v48.Y + d1 / 2), v58, 90, 20, 1, height, arrowsize, exline, "h3=" + Math.Round(h3, 1), "", "");
                fun.dimrot1(dxf, v67, v78, 90, 20, 1, height, arrowsize, exline, "b1=" + Math.Round(b1, 1), "", "");

                //角度标注
                fun.jdbz2(dxf, new Line(v66, fun.Polar(v66, 153 * pi / 180, 0.1)), new Line(v48, new Vector2(v48.X - 0.1, v48.Y)), 25, height, arrowsize, exline, "27°±3°", "", "");

                //形位公差
                fun.gcbz(dxf, new Vector2(v78.X - 15, v78.Y), 20, -90, 3, 0, 5, arrowsize, 1, "A", "0.05", height, "dcd", 0.5);

                //基准
                fun.jz(dxf, new Vector2(v45.X, v45.Y), -90, 5, "B");
            }

            double isframe = Convert.ToInt32(data["isframe"]);
            String isframe_chose = Convert.ToString(data["isframe_chose"]);
            Vector2 p0 = new Vector2(0, 0);
            if (isframe == 1)
            {
                if (isframe_chose.Equals("0"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA0X(dxf, new Vector2(p0.X - 1189 / 2.0, p0.Y + 841 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("1"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA1X(dxf, new Vector2(p0.X - 841 / 2.0, p0.Y + 594 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("2"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA2X(dxf, new Vector2(p0.X - 594 / 2.0, p0.Y + 420 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("3"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA3X(dxf, new Vector2(p0.X - 420 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4X"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4X(dxf, new Vector2(p0.X - 297 / 2.0, p0.Y + 210 / 2.0 - 10 * 2.26), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4Y"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4Y(dxf, new Vector2(p0.X - 210 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }
            }



            //定义格式，根据路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }

    }
}
